package com.qf.hospital.system.oss;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class FileUploadUtil {



    private static String endpoint = "oss-cn-beijing.aliyuncs.com";
    private static String accessKeyId = "LTAI4FsRfQ5wuk1K21n4Chpb";
    private static String accessKeySecret = "QGnITifAFBJOGiQD1Tw1wa5g2dKRzt";

    private static String bucketName = "bkjava";
    private static String key = "images";   //  上传到OSS上的文件目录以及名称!


    public static void main(String[] args) throws FileNotFoundException {
        // 创建OSS对象,用于和OSS服务器交互
        OSS client = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);

        // 通过字节流的形式,将文件上传到阿里云的OSS
        FileInputStream inputStream = new FileInputStream("D:\\pic\\91b79466-a838-4db7-b7a4-f769f86799f4.jpg");
        client.putObject(bucketName, key + "/91b79466-a838-4db7-b7a4-f769f86799f4.jpg", inputStream);
        String url = "http://bkjava.oss-cn-beijing.aliyuncs.com/" + key + "/91b79466-a838-4db7-b7a4-f769f86799f4.jpg";
        System.out.println(url);
    }

}
